#-*- coding: UTF-8 -*-

from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import User

# Create your models here.

class device(models.Model):
    typee = ((U'阿里云','阿里云'),(U'腾讯云','腾讯云'),(U'本地虚拟机','本地虚拟机'),(U'贵阳机房','贵阳机房'),)
    device_hostname = models.CharField(verbose_name='主机名称',max_length=255)
    #choices扎到type元组并调用相关内容
    device_type = models.CharField(verbose_name='主机类型',max_length=50,choices=typee)
    device_address = models.CharField(verbose_name='主机地址',max_length=255)
    device_port = models.CharField(verbose_name='SSH端口',max_length=50)
    #blank为空表示在form中可以不填
    device_contact = models.CharField(verbose_name='登记人员',max_length=50,blank=True)
    #default表示默认值
    device_system = models.CharField(verbose_name='系统版本',max_length=50,default='Centos6.8')
    device_remarks = models.CharField(verbose_name='备注',max_length=255,blank=True)
    device_signtime = models.DateField(auto_now_add = True)

    def __str__(self):
        return self.device_address


class service(models.Model):
    device = models.ForeignKey(device,on_delete=models.PROTECT)

    project = ((U'花无缺','花无缺'),(U'友邻','友邻'),(U'停车场','停车场'),(U'其他','其他'),)
    typee = ((U'数据库','数据库'),(U'JAVA','JAVA'),(U'PHP','PHP'),(U'NGINX','NGINX'),(U'缓存服务','缓存服务'),(U'图片服务器','图片服务器'),(U'其他','其他'),)
    status = ((U'启动','启动'),(U'未启动','未启动'),)
    
    service_name = models.CharField(verbose_name='服务名称',max_length=255)
    service_port = models.CharField(verbose_name='端口号',max_length=50)
    service_project = models.CharField(verbose_name='所属项目',max_length=50,choices=project)
    service_type = models.CharField(verbose_name='服务类型',max_length=50,choices=typee)
    service_status = models.CharField(verbose_name='服务状态',max_length=50,choices=status)
    service_contact = models.CharField(verbose_name='登记人员',max_length=50,blank=True)   

    def __str__(self):
        return self.service_project

class Employee(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    responsibility = models.CharField(max_length=100,blank=True)

    def __str__(self):
        return self.user.username

class Task(models.Model):
    task_member = models.ManyToManyField(Employee)
    category = ((U'业务部署','业务部署'),(U'业务下线','业务下线'),(U'日常维护','日常维护'),)

    task_code = models.CharField(max_length=30,default='error_code')
    task_title = models.CharField(verbose_name='任务名称',max_length=100)
    task_category = models.CharField(verbose_name='任务分类',max_length=100,choices=category,default='日常维护')
    task_contacts = models.TextField(verbose_name='联系人',blank=True)
    task_status = models.CharField(verbose_name='处理中',max_length=20,default='处理中')
    task_signer = models.CharField(max_length=30,default='system')
    task_signtime = models.DateField(auto_now_add=True)

    def __str__(self):
        return self.task_title

class Process(models.Model):
    task = models.ForeignKey(Task)
    procss_content = models.TextField(blank=True)
    process_signtime = models.DateField(auto_now_add=True)
    process_signer = models.CharField(max_length=30,default='system')
  
    def __str__(self):
        return self.process_content

class Upload(models.Model):
    task = models.ForeignKey(Task)
    upload_title = models.CharField(max_length=255)
    upload_path = models.CharField(max_length=255)
    upload_signtime = models.DateTimeField(auto_now_add=True,null=True)

    def __str__(self):
        return self.upload_title
    
